package org.springframework.parser;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.IOException;
import java.io.InputStream;

public class SpringConfigParser {

    public static String parseComponentScanPackage(String springConfig)  {
        InputStream resourceAsStream=null;
        try{
            SAXReader reader=new SAXReader();
            resourceAsStream = SpringConfigParser.class.getClassLoader().getResourceAsStream(springConfig);
            Document document = reader.read(resourceAsStream);
            Element rootElement = document.getRootElement();
            Element element = rootElement.element("component-scan");
            String componentScanPackage = element.attributeValue("base-package");
            return componentScanPackage;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                resourceAsStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return "";
    }
}
